package com.glsc.ngateway.common.base.domain.mysql.gateway.oaflow.xirtrade;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.glsc.ngateway.common.base.domain.mysql.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import java.time.LocalDateTime;

/**
 * 衡泰xir指令同步配置表
 * @author xuchang
 */
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@Entity
@Where(clause = "deleted = 0")
@SQLDelete(sql = "update t_oa_flow_xir_trade_config set deleted = UNIX_TIMESTAMP(NOW()), handled = 0 where id=?")
@SQLDeleteAll(sql = "update t_oa_flow_xir_trade_config set deleted = UNIX_TIMESTAMP(NOW()), handled = 0 where id=?")
@Table(name = "t_oa_flow_xir_trade_config", indexes = {@Index(name = "UK_XIRBIZTYPE_WORKFLOWID", columnList = "xir_biz_type, workflow_id, deleted", unique = true)})
public class TOaFlowXirTradeConfig extends BaseEntity {

    private static final long serialVersionUID = -3264094474527903316L;

    @NotBlank
    @Column(name = "xir_biz_type", columnDefinition = "varchar(32) not null")
    private String xirBizType;

    @NotBlank
    @Column(name = "workflow_id", columnDefinition = "varchar(255) not null")
    private String workflowId;

    @NotBlank
    @Column(name = "workflow_type", columnDefinition = "varchar(255) not null")
    private String workflowType;

    @Column(name = "description", columnDefinition = "varchar(255)")
    private String description;
    //TODO:允许多配置人员
    @NotBlank
    @Column(name = "oa_flow_creator", columnDefinition = "varchar(32) not null comment 'oa流程创建人'")
    private String oaFlowCreator;

    @NotBlank
    @Column(name="account_type", columnDefinition = "varchar(64) not null comment '账号类型'")
    private String accountType;

    @NotBlank
    @Column(name="fund_account", columnDefinition = "varchar(64) not null comment '配置值'")
    private String account;

    @Column(name = "begin_time", columnDefinition = "datetime comment '生效时间'")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    private LocalDateTime beginTime;

    @Column(name = "end_time", columnDefinition = "datetime comment '失效时间'")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    private LocalDateTime endTime;
}
